<!DOCTYPE html>
<html>
  <head>
    <title>medicalCard.html</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<style type="text/css">
    body {
        width: 100%;
        height: 100%;
        background: #fff;
    }
    /*表格样式*/
</style>
  <link rel="stylesheet" href="/Hospital/lib/layui-v2.1.6/layui/css/layui.css" media="all">
  <body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>诊疗卡信息</legend>
    </fieldset>
    <table id="medicalCardTable" class="layui-table"  lay-filter="medicalListen"></table>
  </body>
<script src="/Hospital/lib/jquery.min.js" charset="utf-8"></script>
<script src="/Hospital/lib/layui-v2.1.6/layui/layui.js" charset="utf-8"></script>
<script id="operator" type="text/html">
	<a class="layui-btn layui-btn-mini" lay-event="create">治疗</a>
</script>
<script>
	var medicalCardClientId=JSON.parse(localStorage.getItem("medicalCardClientId"));
	localStorage.removeItem("medicalCardClientId");
	layui.use(['table'],function(){
		var table = layui.table;
		initTable();
		
		function initTable(){
			var height=window.innerHeight*0.8;
            var tableWidth=window.innerWidth*0.14;
			table.render({
				id:"medicalCardTable",
                elem:"#medicalCardTable",
                page:true,
                limit:10,
                center:true,
                height:height,
                cols:[[
					{field:'clientName',width:tableWidth,title:'姓名',align:'center'},
                    {field:'projectName',width:tableWidth,title:'治疗项目',align:'center'},
                    {field:'unitPrice',width:tableWidth,title:'治疗价格/次',align:'center'},
                    {field:'totalNumber',width:tableWidth,title:'总次数',align:'center'},
                    {field:'restNumber',width:tableWidth,title:'剩余次数',align:'center'},
                    {field:'startTime',width:tableWidth,title:'开始日期',align:'center'},
                    {field:'deadline',width:tableWidth,title:'截止日期',align:'center'},
                    {toolbar:'#operator',width:70,title:'操作',fixed: 'right'},
                ]],
                url:"/Hospital/medicalCardController/getMedicalCardInfo",
                method:"POST",
                where:medicalCardClientId,
                response:{
                	statusName:"code",
                	statusCode:200,
                	countName:'total',
                	msgName:"msg",
                	dataName:"result"
                }
			});
			
			//监听工具条 lay-filter
			table.on('tool(medicalListen)', function(obj){
				var data = obj.data;
				localStorage.setItem("medicalCardDetail", JSON.stringify(data));
				if(obj.event === 'create'){
					//治疗按钮点击事件
					initCreateFrame(data);
			  	};
			});
		}
		
		function initCreateFrame() {
			layer.open({
				type : 2,
				title : "录入病人治疗信息窗口",
				area : ["378px","418px"],
				content : '/Hospital/views/treatInfoManager/createTreatInfo.html',
				btn : ["确认","取消"],
				btnAlign : "r",
				resize : false,
				yes : function(index, layero) {
					var param = $(layero).find("iframe")[0].contentWindow.getParam();
					var mainFrame = index;
					//数据验证
					if(!vertify(param)) {
						return;
					}
					
					$.ajax({
						type : "post",
						data : param,
						url : "/Hospital/medicalCardController/createTreatInfo",
						success : function(response) {
							if(response.code == 405) {
								layer.msg("请重新登录");
								return;
							}
							if(response.code == 200) {
								table.reload('medicalCardTable', {
									url:"/Hospital/medicalCardController/getMedicalCardInfo",
					                method:"POST",
					                where:medicalCardClientId,
					                response:{
					                	statusName:"code",
					                	statusCode:200,
					                	countName:'total',
					                	msgName:"msg",
					                	dataName:"result"
					                }
								});
								
								layer.msg("录入成功");
								layer.close(index);
							}
						}
					});
				},
				cancel : function(index, layero) {
					//左上角X关闭按钮
					localStorage.removeItem("dpmDetail");
					layer.close(index);
				},
				btn2 : function(index, layero) {
					//取消按钮
					localStorage.removeItem("dpmDetail");
					layer.close(index);
				}
			});
		}
		
		
	});
	
	function vertify(param) {
		if(param.projectId == "" || param.projectId.length == 0) {
			return false;
		}
		if(param.clientId == "" || param.clientId.length == 0) {
			return false;
		}
		if(param.excutorId == "" || param.excutorId.length == 0) {
			return false;
		}
		return true;
	}
</script>
</html>
